package zry.Operate;

import zry.Search.*;
import zry.Achievement.*;
import zry.Achievement.Other.*;
import zry.Achievement.Patent.*;
import zry.Achievement.Platform.*;
import zry.Achievement.Report.*;
import zry.Achievement.Reward.*;
import zry.Achievement.Standard.*;
import zry.Achievement.Textbook.*;
import zry.Achievement.Thesis.*;
import zry.User.Teacher.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class FinalReview {
    public void FinalReview() {
        AchievementDAO achievementDAO = new AchievementDAOImpl();
        List<Achievement> achievements = achievementDAO.getAllAchievements();

        //去掉初审没有通过或者未初审的申请
        achievements.removeIf(a -> !a.getP_review().equals(1));

        System.out.println("成果id\t\t成果类型\t\t学生id\t\t初审结果\t\t终审结果");
        System.out.println(" " + achievements.toString().replaceAll("\\[", "").replaceAll(",", "").replaceAll("]", ""));

        //将成果认定id存入一个list，只能终审这部分
        List<String> achievementIds = new ArrayList<>();
        for (Achievement a : achievements) {
            achievementIds.add(a.getA_id());
        }
        System.out.println("请输入终审的成果id（输入-1退出）");
        Scanner scanner = new Scanner(System.in);
        while (true) {
            String input = scanner.nextLine();
            if (input.equals("-1")) break;
            //只有输入的成果id在list中，才能正确显示
            if (achievementIds.contains(input)) {
                Achievement achievement = achievementDAO.getAchievement(input);
                System.out.println("成果id\t\t成果类型\t\t用户id\t\t初审结果\t\t终审结果");
                System.out.println(achievement);
                switch (achievement.getA_type()) {
                    case "论文":
                        ThesisDAO thesisDAO = new ThesisDAOImpl();
                        Thesis thesis = thesisDAO.getThesis(input);
                        System.out.println(thesis);
                        break;
                    case "教材":
                        TextbookDAO textbookDAO = new TextbookDAOImpl();
                        Textbook textbook = textbookDAO.getTextbook(input);
                        System.out.println(textbook);
                        break;
                    case "标准":
                        StandardDAO standardDAO = new StandardDAOImpl();
                        Standard standard = standardDAO.getStandard(input);
                        System.out.println(standard);
                        break;
                    case "奖励":
                        RewardDAO rewardDAO = new RewardDAOImpl();
                        Reward reward = rewardDAO.getReward(input);
                        System.out.println(reward);
                        break;
                    case "报告":
                        ReportDAO reportDAO = new ReportDAOImpl();
                        Report report = reportDAO.getReport(input);
                        System.out.println(report);
                        break;
                    case "平台":
                        PlatformDAO platformDAO = new PlatformDAOImpl();
                        Platform platform = platformDAO.getPlatform(input);
                        System.out.println(platform);
                        break;
                    case "专利":
                        PatentDAO patentDAO = new PatentDAOImpl();
                        Patent patent = patentDAO.getPatent(input);
                        System.out.println(patent);
                        break;
                    case "其他":
                        OtherDAO otherDAO = new OtherDAOImpl();
                        Other other = otherDAO.getOther(input);
                        System.out.println(other);
                        break;
                }
                System.out.println("是否通过（y/n）");
                input = scanner.nextLine();
                if (input.equals("y")) {
                    achievement.setF_review(1);
                    achievementDAO.updateAchievement(achievement);
                    System.out.println("终审结束");
                } else if (input.equals("n")) {
                    achievement.setF_review(-1);
                    achievementDAO.updateAchievement(achievement);
                    System.out.println("终审结束");
                } else {
                    System.out.println("输入错误");
                }

                break;
            } else {
                System.out.println("成果id输入错误，请输入正确的成果id");
            }
        }
    }
}
